package ReflectDemo;

public class Test05 {
    public static void main(String[] args) throws ClassNotFoundException {
        Person person = new Student();
        System.out.println("The person is : " + person.name);

        //方式一：通过对象获得
        Class c1 = person.getClass();
        System.out.println(c1.hashCode());

        //方式二：forName获得
        Class c2 = Class.forName("ReflectDemo.Student");
        System.out.println(c2.hashCode());

        //方式三：通过类名.class获得
        Class<Student> c3 = Student.class;
        System.out.println(c3.hashCode());

        //方式四：基本内置类型的包装类都有一个Type属性
        Class c4 = Integer.TYPE;
        System.out.println(c4);

        //获得父类类型
        Class c5 = c1.getSuperclass();
        System.out.println(c5);
    }
}
class Person{
     int id;
     String name;

    public Person() {
    }

    public Person(int id, String name) {
        this.id = id;
        this.name = name;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "Person{" +
                "id=" + id +
                ", name='" + name + '\'' +
                '}';
    }
}


class Student extends Person{
    public Student(){
        this.name = "student";
    }
}
class Teacher extends Person{
    public Teacher(){
        this.name = "teacher";
    }

}